package com.scalar.forecast.forecastEntry;

import java.util.Comparator;
import java.io.Serializable;

/**
 * User: Sujan Kumar
 * Date: Feb 11, 2005
 * Time: 3:31:34 PM
 */
public class SearchFieldListComparator implements Comparator, Serializable
{
    int result = 0;
    public int compare( Object searchField1, Object searchField2 )
    {
        if ( !( searchField1 instanceof SearchField ) || !( searchField2 instanceof SearchField ) )
        {
            throw new  ClassCastException ( );
        }

        int order1 = ( ( SearchField )searchField1).getSortOrder();
        int order2 = ( ( SearchField )searchField2).getSortOrder();
        if( ( order1 == 0 ) && ( order2 == 0 ) )
        {
            result = 0;
        }
        else if( order1 == 0 )
        {
            result = 1;
        }
        else if( order2 == 0 )
        {
            result = -1;
        }
        else
        {
            result = order1 - order2;
        }
        return result;
    }

}

